
class RgbMatrix:

    def __init__(self, dimention, values=None):
        self.dimention = dimention
        if values != None:
            self.values = values
        else:
             self.values = []            
             self.initValues()

    def initValues(self):
        for index in range(self.dimention * self.dimention):
            self.values.append((0,0,0))
       
    def setIndex(self, i, j, value):
        index = i * self.dimention + j
        self.values[index] = value

    def getDifferenceMatrix(self, otherMatrix):
        assert (self.dimention == otherMatrix.dimention)
        assert (type(otherMatrix == 'RgbMatrix'))
        
        difference=[(abs(value[0] - otherValue[0]), \
                     abs(value[1] - otherValue[1]), \
                     abs(value[2] - otherValue[2])) \
                    for value,otherValue in zip(self.values, otherMatrix.values)]
           
        """for value,otherValue in zip(self.values, otherMatrix.values):
                rgbDifference = (abs(value[0] - otherValue[0]),\
                                 abs(value[1] - otherValue[1]),\
                                 abs(value[2] - otherValue[2]))
                difference.append(rgbDifference)"""
               
        matrix = RgbMatrix(self.dimention, difference)
        return matrix

    def applyUnaryFunction(self, func):
        ls = map(func, self.values)
        return ls    
